package com.ease.business.dpi.service;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;

import com.ease.common.util.DateFormatUtil;
import com.ease.common.util.Detect;
import com.ease.common.util.FileUtil;
import com.ease.common.vo.MapParameter;
import com.ease.dao.JdbcTemplateDataAccessObject;
import com.obas.test.ApplicationContextUserContextTest;

public class X_USERAPP_MINUTE_RAW_initilizer extends ApplicationContextUserContextTest {

	@Autowired
	JdbcTemplateDataAccessObject jdbcTemplateDataAccessObject;

	@Test
	public void test() {

		String string = FileUtil.readClassPathResourceToString(X_USERAPP_MINUTE_RAW_initilizer.class, "X_USERAPP_MINUTE_RAW.txt");

		String[] rows = StringUtils.delimitedListToStringArray(string, "\r\n");
		MapParameter parameter = null;
		if (null != rows) {
			for (String row : rows) {
				if(row.startsWith("#")) {
					continue;
				}
				String[] values = StringUtils.commaDelimitedListToStringArray(row);
				if (null == values) {
					continue;
				}

				parameter = new MapParameter();
				parameter.put("TIMESTAMP",           DateFormatUtil.toDatetime("2013-05-05 11:11:11"));
				parameter.put("DURATION",             Detect.trim(values[1]));
				parameter.put("AREACODE",             Detect.trim(values[2]));
				parameter.put("PROTOCAL",             Detect.trim(values[3]));
				parameter.put("INDICATORTYPE",        Detect.trim(values[4]));
				parameter.put("USERNAME",             Detect.trim(values[5]));
				parameter.put("USERMACADDRESS",       Detect.trim(values[6]));
				parameter.put("BANDTYPE",             Detect.trim(values[7]));
				parameter.put("BANDATTR",             Detect.trim(values[8]));
				parameter.put("IPSOURCE",             Detect.trim(values[9]));
				parameter.put("PORTSOURCE",           Detect.trim(values[10]));
				parameter.put("BUSINESSNAME",         Detect.trim(values[11]));
				parameter.put("APPNAME",              Detect.trim(values[12]));
				parameter.put("VALUE0",               Detect.trim(values[13]));
				parameter.put("VALUE1",               Detect.trim(values[14]));
				parameter.put("VALUE2",               Detect.trim(values[15]));
				parameter.put("VALUE3",               Detect.trim(values[16]));
				parameter.put("VALUE4",               Detect.trim(values[17]));
				parameter.put("VALUE5",               Detect.trim(values[18]));
				parameter.put("VALUE6",               Detect.trim(values[19]));
				parameter.put("VALUE7",               Detect.trim(values[20]));
				parameter.put("VALUE8",               Detect.trim(values[21]));
				parameter.put("VALUE9",               Detect.trim(values[22]));
				parameter.put("VALUE10",              Detect.trim(values[23]));
				parameter.put("VALUE11",              Detect.trim(values[24]));
//				parameter.put("SUMMATION",            Detect.trim(values[25]));
				parameter.put("BATCHTIMESTAMP",       DateFormatUtil.toDatetime("2013-05-05 11:11:11"));
				//
				jdbcTemplateDataAccessObject.create("INSERT INTO X_USERAPP_MINUTE_RAW (ID,TIMESTAMP,DURATION,AREACODE,PROTOCAL,INDICATORTYPE,USERNAME,USERMACADDRESS,BANDTYPE,BANDATTR,IPSOURCE,PORTSOURCE,BUSINESSNAME,APPNAME,VALUE0,VALUE1,VALUE2,VALUE3,VALUE4,VALUE5,VALUE6,VALUE7,VALUE8,VALUE9,VALUE10,VALUE11,BATCHTIMESTAMP)VALUES(SEQ_X_USERAPP_MINUTE_RAW.NEXTVAL,:TIMESTAMP,:DURATION,:AREACODE,:PROTOCAL,:INDICATORTYPE,:USERNAME,:USERMACADDRESS,:BANDTYPE,:BANDATTR,:IPSOURCE,:PORTSOURCE,:BUSINESSNAME,:APPNAME,:VALUE0,:VALUE1,:VALUE2,:VALUE3,:VALUE4,:VALUE5,:VALUE6,:VALUE7,:VALUE8,:VALUE9,:VALUE10,:VALUE11,:BATCHTIMESTAMP)",
						parameter);

			}
		}

	}

}